package com.core.reach.cloudhub.service.impl;

import com.core.reach.cloudhub.service.MessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: EnableBinding注解开启消息驱动的binder，Source标明这是一个消息推送的channel
 * @date 2020/3/27 13:55
 **/
@Slf4j
@EnableBinding(Source.class)
public class MessageProviderImpl implements MessageProvider {

    /**
     * 消息发送管道
     */
    @Resource
    private MessageChannel output;

    @Override
    public Boolean send() {
        String serialId = UUID.randomUUID().toString();
        boolean send = output.send(MessageBuilder.withPayload(serialId).build());
        log.info("*********发送消息流水号serialId：{},发送结果为：{}", serialId, send);
        return send;
    }

}
